<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>게시판 글쓰기</title>
</head>
<body>
<h1>게시판 글쓰기</h1>
<%
	String DRV = "org.mariadb.jdbc.Driver";
	String URL = "jdbc:mariadb://localhost:3306/untiring07?user=untiring07&password=123456";
	String SQL = "insert into boardv4 (title, uid, contents) values (?,?,?)";
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	String title = null;
	String uid = null;
	String contents = null;
%>
<%
	request.setCharacterEncoding("UTF-8");
	title = request.getParameter("title");
	uid = request.getParameter("uid");
	contents = request.getParameter("contents");
	//  Enter 키를 이용해서 입력한 줄바꿈은
	// html 상에서는 보이지 않음
	// 따라서, 이것을 <br /> 로 바꿔야 함
	contents = contents.replace("\r\n", "<br />");
%>
<%
	try {
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		pstmt = conn.prepareStatement(SQL);
			pstmt.setString(1, title);
			pstmt.setString(2, uid);
			pstmt.setString(3, contents);
		pstmt.executeUpdate();
		out.print("<h3 style='color:red'>성공적으로 글이 등록됨!!</h3>");
	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		if (pstmt != null) try { pstmt.close(); } catch (Exception e) { }
		if (conn != null) try { conn.close(); } catch (Exception e) { }
	}
%>
<%
	response.sendRedirect("list.jsp");
%>







</body>
</html>